As an encoder used to detect the rotation of a motor, a conventional magnetic encoder provided with a magnetic field sensor is known. The magnetic encoder detects the rotation of the motor by detecting the magnetic field of a permanent magnet, which revolves along with the rotation of the motor, with the magnetic field sensor (see Japanese Patent No. 4622487, for example).